#!/bin/bash
set -e

source $(dirname $0)/version

cd $(dirname $0)/..

PROJECT=`basename "$PWD"`

TAG=${TAG:-${VERSION}}
REPO=${REPO:-longhornio}
IMAGE=${REPO}/${PROJECT}:${TAG}

if [ ! -x ./bin/longhorn ]; then
    ./scripts/build
fi

cp /usr/src/tgt/pkg/tgt_*.deb ./bin/
cp /usr/local/bin/longhorn-instance-manager ./bin/

docker build -t ${IMAGE} -f package/Dockerfile .

echo Built ${IMAGE}

echo ${IMAGE} > ./bin/latest_image
